package com.excuse.excusebuilder.view.activity;

import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.excuse.excusebuilder.R;
import com.excuse.excusebuilder.base.BaseActivity;
import com.excuse.excusebuilder.impl.view.MainActivityInterface;
import com.excuse.excusebuilder.presenter.MainActivityPresenter;

import butterknife.BindView;
import butterknife.OnClick;


public class MainActivity extends BaseActivity implements MainActivityInterface{

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.frame)
    FrameLayout frame;
    @BindView(R.id.home_img)
    ImageView homeImg;
    @BindView(R.id.home_text)
    TextView homeText;
    @BindView(R.id.home_layout)
    LinearLayout homeLayout;
    @BindView(R.id.community_img)
    ImageView communityImg;
    @BindView(R.id.community_text)
    TextView communityText;
    @BindView(R.id.community_layout)
    LinearLayout communityLayout;
    @BindView(R.id.mine_img)
    ImageView mineImg;
    @BindView(R.id.mine_text)
    TextView mineText;
    @BindView(R.id.mine_layout)
    LinearLayout mineLayout;

    private MainActivityPresenter presenter;

    @Override
    protected void initData() {
        clickHome();
        initPresenter();
    }

    private void initPresenter() {
        presenter = new MainActivityPresenter(context,this);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_main;
    }

    @OnClick({R.id.home_layout, R.id.community_layout, R.id.mine_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.home_layout:
                reductionBottom();
                clickHome();
                presenter.setHomeFragment();
                break;
            case R.id.community_layout:
                reductionBottom();
                clickCommunity();
                presenter.setCommunityFragment();
                break;
            case R.id.mine_layout:
                reductionBottom();
                clickMine();
                presenter.setMineFragment();
                break;
        }
    }

    private void clickMine() {
        mineImg.setImageResource(R.mipmap.people_click);
        mineText.setTextColor(getResources().getColor(R.color.md_light_blue_500));
        title.setText(R.string.mine_text);
    }

    private void clickCommunity() {
        communityImg.setImageResource(R.mipmap.community_click);
        communityText.setTextColor(getResources().getColor(R.color.md_light_blue_500));
        title.setText(R.string.community_text);
    }

    private void clickHome() {
        homeImg.setImageResource(R.mipmap.home_click);
        homeText.setTextColor(getResources().getColor(R.color.md_light_blue_500));
        title.setText(R.string.home_text);
    }

    private void reductionBottom() {
        homeImg.setImageResource(R.mipmap.home);
        communityImg.setImageResource(R.mipmap.community);
        mineImg.setImageResource(R.mipmap.people);
        homeText.setTextColor(getResources().getColor(R.color.md_grey_600));
        communityText.setTextColor(getResources().getColor(R.color.md_grey_600));
        mineText.setTextColor(getResources().getColor(R.color.md_grey_600));
    }

    @Override
    public FragmentManager getActivityFragmentManager() {
        return getSupportFragmentManager();
    }
}
